﻿using System;
using System.Net;
using System.Linq;
using Hydra.Shell.Attributes;
using System.Diagnostics;

namespace Hydra.Shell
{
    public static class GuidExtensions
    {
        [DebuggerStepThrough()]
        public static bool HasGuid(this Type type)
        {
            return type.GetCustomAttributes(true).Any(a => a is GuidAttribute);
        }

        [DebuggerStepThrough()]
        public static Guid GetGuid(this Type type)
        {
            var guidAttribute = (GuidAttribute) type.GetCustomAttributes(true).SingleOrDefault(a => a is GuidAttribute);

            if (guidAttribute != null)
            {
                return Guid.Parse(guidAttribute.Value);
            }
            else
            {
                throw new Exception("Construct does not have an GuidAttribute");
            }
        }
    }
}
